package com.hxzy.shop.dto.coupon.convert;


import com.hxzy.shop.dto.coupon.req.PayPolitelyEditReq;
import com.hxzy.shop.dto.coupon.req.PayPolitelyListReq;
import com.hxzy.shop.dto.coupon.req.PayPolitelySaveReq;
import com.hxzy.shop.dto.coupon.resp.PayPolitelyDetailResp;
import com.hxzy.shop.dto.coupon.resp.PayPolitelyListResp;
import com.hxzy.shop.entity.PayPolitely;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

/**
 * @Author ht
 * @Date 2021/7/8 14:55
 * @Version 1.0
 */
@Mapper
public abstract class PayPolitelyConvert {
    public static PayPolitelyConvert INSTANCE = Mappers.getMapper(PayPolitelyConvert.class);

    public abstract List<PayPolitelyListResp> payPolitely2PayPolitelyListResp(List<PayPolitely> payPolitely);

    @AfterMapping
    public void req2PayPolitely(PayPolitelyListReq payPolitelyListReq, @MappingTarget PayPolitelyListResp payPolitelyListResp) {
        Date newDate = new Date();
        if (payPolitelyListResp.getActivityStartTime().after(newDate)) {
            payPolitelyListResp.setCouponTimeStatus(1);
        } else if (!payPolitelyListResp.getState() || payPolitelyListResp.getActivityEndTime().before(newDate)) {
            payPolitelyListResp.setCouponTimeStatus(3);
        } else {
            payPolitelyListResp.setCouponTimeStatus(2);
        }
    }

    //保存请求
    public abstract PayPolitely payPolitelySaveReq2PayPolitely(PayPolitelySaveReq payPolitelySaveReq);

    public abstract PayPolitelyDetailResp payPolitely2DetailResp(PayPolitely payPolitely);

    public abstract PayPolitely payPolitelyEditReq2PayPolitely(PayPolitelyEditReq payPolitelyEditReq);

}
